package com.StarStudio.DAO;


import com.ruoyi.common.core.Entity.PanicBuyingGoods;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PanicBuyingGoodsDAO {

    List<PanicBuyingGoods> findPanicBuyingGoodsList(PanicBuyingGoods panicBuyingGoods);

    @Select("select count(panic_buying_goods_id) from panic_buying_goods where del_flag = false")
    long findTotalRecord();

    @Select("select * from panic_buying_goods where goods_id = #{goods_id}")
    PanicBuyingGoods findByGoods_id(long goods_id);

    @Update("update panic_buying_goods set goods_id = #{goods_id},panic_buying_price = #{panic_buying_price}," +
            "panic_buying_goods_stock = #{panic_buying_goods_stock}, panic_buying_start_time = #{panic_buying_start_time}," +
            "panic_buying_end_time = #{panic_buying_end_time},panic_buying_status = #{panic_buying_status},del_flag = #{del_flag} where panic_buying_goods_id = #{panic_buying_goods_id}")
    int updatePanicBuyingGoods(PanicBuyingGoods panicBuyingGoods);

    @Select("select * from panic_buying_goods where del_flag = false")
    List<PanicBuyingGoods> PanicBuyingGoodsList();

    @Select("select * from panic_buying_goods where panic_buying_status = #{status}")
    List<PanicBuyingGoods> findByStatus(int status);

    @Insert("insert into panic_buying_goods values (null,#{goods_id},#{panic_buying_price},#{panic_buying_goods_stock},#{panic_buying_start_time}," +
            "#{panic_buying_end_time},#{panic_buying_status},#{del_flag})")
    @Options(useGeneratedKeys = true,keyColumn = "panic_buying_goods_id",keyProperty = "panic_buying_goods_id")
    void AddPanicBuyingGoods(PanicBuyingGoods panicBuyingGoods);

//    @Delete("delete from panic_buying_goods where panic_buying_goods_id = #{panic_buying_goods_id}")
    @Update("update panic_buying_goods set del_flag = true and panic_buying_goods_stock = 0")
    void DeletePanicBuyingGoods(long panic_buying_goods_id);

    @Select("select panic_buying_goods_stock from panic_buying_goods where panic_buying_goods_id = #{Panic_buying_goods_id}")
    int findByPanic_buying_goods_stockByPanic_buying_goods_id(long Panic_buying_goods_id);

    @Select("select goods_id from panic_buying_goods where panic_buying_goods_id = #{panic_buying_goods_id}")
    long findGoodsIdByPBGId(long panic_buying_goods_id);

    @Select("select panic_buying_goods_stock from panic_buying_goods where goods_id = #{goods_id} and del_flag = false")
    int findPBGoodsStockByGoodsId(long goods_id);
}
